﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using Model;

namespace TaxiDispatchClient
{
    public partial class TaxiFrom : DevExpress.XtraEditors.XtraForm
    {
        public TaxiFrom()
        {
            InitializeComponent();

        }
        private DataTable _dtGroup;

        private Thread _thread;
        private bool _isLoad;
        private bool _isAdd;
        


        private void Taxi_Load(object sender, EventArgs e)
        {
           

            //foreach (string s in MainForm.CompanyList)
            //{
            //    comboBoxEdit_company.Properties.Items.Add(s);
            //}

            _isLoad = true;
            _thread = new Thread(BindGrid);
            _thread.Start();
        }

        private void BindControlData()
        {
            //BeginInvoke(new MethodInvoker(() =>
            //{
            //    gridView1.Columns["id"].Caption = "ID号";
            //    gridView1.Columns["id"].Width = 40;
            //    gridView1.Columns["id"].AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
            //    gridView1.Columns["id"].AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            //    gridView1.Columns["TaxiNo"].Caption = "出租车牌照";
            //    gridView1.Columns["TaxiNo"].Width = 55;
            //    gridView1.Columns["TaxiType"].Caption = "出租车车型（颜色）";
            //    gridView1.Columns["TaxiType"].Width = 90;
            //    gridView1.Columns["CompanyName"].Caption = "所属公司";
            //    gridView1.Columns["Taxigroup"].Caption = "所属广告分组";
            //    gridView1.Columns["TaxiGroupid"].Visible = false;
            //    gridView1.Columns["ServerId"].Visible = false;
            //}));   
         

            DataSet ds = MainForm.PositionService.TaxiGroupGetList("");

            if (ds != null && ds.Tables.Count == 1)
            {

                _dtGroup = ds.Tables[0];
                if (_dtGroup.Rows.Count <= 0)
                    return;
                for (int i = 0; i < _dtGroup.Rows.Count; i++)
                {
                    string group = _dtGroup.Rows[i]["TaxiGroup"].ToString();
                    BeginInvoke(new MethodInvoker(() =>
                    {
                        comboBoxEdit_taxigroup.Properties.Items.Add(group);
                    }));
                }
            }

            //if (MainForm.MyUserInfo.CompanyName == Service.PowerConfig.MainCompanyName)
            //{
            //    DataSet dsCompany = MainForm.PositionService.CompanyGetList("");
            //    if (dsCompany != null && dsCompany.Tables.Count > 0)
            //    {
            //        foreach (DataRow row in dsCompany.Tables[0].Rows)
            //        {
            //            string id = row["Id"].ToString();
            //            string name = row["CompanyName"].ToString();
            //            ImageComboBoxItem item = new ImageComboBoxItem();
            //            item.Description = name;
            //            item.Value = id;
            //            BeginInvoke(new MethodInvoker(() =>
            //            {
            //                comboBoxEdit_company.Properties.Items.Add(item);
            //            }));
            //        }
            //    }
               
            //}
            //else
            //{
            //    ImageComboBoxItem item = new ImageComboBoxItem();
            //    item.Description = MainForm.MyUserInfo.CompanyName;
            //    item.Value = MainForm.MyUserInfo.CompanyId;
            //    BeginInvoke(new MethodInvoker(() =>
            //    {
            //        comboBoxEdit_company.Properties.Items.Add(item);
            //        comboBoxEdit_company.SelectedIndex = 0;
            //    }));
            //    BeginInvoke(new MethodInvoker(() =>
            //    {
            //        radioGroup_SelectType.Properties.Items.RemoveAt(2);
            //    }));
            //}

            DataSet dsCompany = new DataSet();

            if (MainForm.MyUserInfo.CompanyName == Service.PowerConfig.MainCompanyName)
            {
                dsCompany = MainForm.PositionService.CompanyGetList("");

            }
            else
            {
                dsCompany = MainForm.PositionService.CompanyGetList(
                    "CompanyName like '" + MainForm.MyUserInfo.CompanyName
                    + "%'");
            }
            if (dsCompany != null && dsCompany.Tables.Count > 0)
            {
                foreach (DataRow row in dsCompany.Tables[0].Rows)
                {
                    string id = row["Id"].ToString();
                    string name = row["CompanyName"].ToString();
                    ImageComboBoxItem item = new ImageComboBoxItem();
                    item.Description = name;
                    item.Value = id;
                    BeginInvoke(new MethodInvoker(() =>
                    {
                        comboBoxEdit_company.Properties.Items.Add(item);
                    }));
                }
            }


             
            ImageComboBoxItem itemNull = new ImageComboBoxItem("未设置", null);
            BeginInvoke(new MethodInvoker(() =>
                        imageCombo_serverList.Properties.Items.Add(itemNull)));
            DataSet dsServers = MainForm.PositionService.ServerConfigGetList("");
            if (dsServers != null && dsServers.Tables.Count > 0)
            {
                foreach (DataRow row in dsServers.Tables[0].Rows)
                {
                    string id = row["id"].ToString();
                    string serverName = row["ServerName"].ToString();
                    ImageComboBoxItem item = new ImageComboBoxItem();
                    item.Description = serverName;
                    item.Value = id;
                    BeginInvoke(new MethodInvoker(() =>
                        imageCombo_serverList.Properties.Items.Add(item)));
                }
            }


          //  BindServers();
        }
        private void BindGrid()
        {
            try
            {
                DataSet ds = new DataSet();
                string parameterVaule = textEdit_condition.Text.Trim();
                string parameter="TaxiNo";
                switch (radioGroup_SelectType.SelectedIndex)
                {
                    case 0:
                        parameter = "TaxiNo";
                        break;
                    case 1:
                        parameter = "TaxiType";
                        break;
                    case 2:
                        parameter = "tc.CompanyName";
                        break;
                }
                //if (radioGroup_SelectType.SelectedIndex == 0)
                //{
                //    parameter = "TaxiNo";
                //}
                //else if (radioGroup_SelectType.SelectedIndex == 1)
                //{
                //    parameter = "TaxiType";
                //}
                //else
                //{
                //    parameter = "tc.CompanyName";
                //}
                //ds = MainForm.PositionService.TaxiInfoGetListWithPar(parameter, parameterVaule);    

                StringBuilder strWhere = new StringBuilder();
                if (parameterVaule  == "")
                {
                    if (MainForm.MyUserInfo.CompanyName != Service.PowerConfig.MainCompanyName)
                    {
                        strWhere.Append(" tc.CompanyName like '");
                        strWhere.Append(MainForm.MyUserInfo.CompanyName);
                        strWhere.Append("%'");                         
                    }                     
                   
                }
                else
                {
                    strWhere.Append(parameter);
                    strWhere.Append(" like '%");
                    strWhere.Append(parameterVaule);
                    strWhere.Append("%' ");
                    if (MainForm.MyUserInfo.CompanyName != Service.PowerConfig.MainCompanyName)
                    {
                        strWhere.Append(" and tc.CompanyName='");
                        strWhere.Append(MainForm.MyUserInfo.CompanyName);
                        strWhere.Append("'");
                    }                               
                }
                ds = MainForm.PositionService.TaxiInfoGetList(strWhere.ToString());
                if(ds!=null && ds.Tables.Count==1)
                BeginInvoke(new MethodInvoker(() =>
                {
                    gridControl1.DataSource = ds.Tables[0];
                    gridView1.GroupPanelText = "出租车列表-共" +ds.Tables[0].Rows.Count+"辆";
                    if(_isLoad)
                    {
                        BindControlData();
                        _isLoad = false;
                    }
                    if(_isAdd)
                    {
                        gridView1.FocusedRowHandle = gridView1.RowCount - 1;
                        _isAdd = false;
                    }
                    //DataRow row = this.gridView1.GetDataRow(this.gridView1.FocusedRowHandle);//
                    //if (row != null)
                    //{
                    //    textEdit_Id.Text = row["id"].ToString();
                    //    textEdit_taxiNo.Text = row["TaxiNo"].ToString();
                    //    textEdit_Type.Text = row["TaxiType"].ToString();
                    //    //textEdit_remark.Text = row["Remark"].ToString();
                     
                    //    btn_modify.Enabled = true;
                    //    string strGroup = row["TaxiGroup"].ToString();
                    //    comboBoxEdit_taxigroup.Text = strGroup;
                    //    imageCombo_serverList.Text = row["ServerId"].ToString();

                    //    string strCompany = row["CompanyId"].ToString();
                    //    comboBoxEdit_company.Text = strCompany;
                    //}
                    btn_select.Enabled = true;
                }));                
            }
            catch (Exception ex)
            {               
               Common.CommonRoutine.HandlingExceptions(ex);
             //  BeginInvoke(new MethodInvoker(() => btn_select.Enabled = true));               
            }
        }

        private void BindServers()
        {
             
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            DataRow row = this.gridView1.GetDataRow(this.gridView1.FocusedRowHandle);//
            if (row != null)
            {
                textEdit_Id.Text = row["id"].ToString();
                textEdit_taxiNo.Text = row["TaxiNo"].ToString();
                textEdit_Type.Text = row["TaxiType"].ToString();
                //textEdit_remark.Text = row["Remark"].ToString();                
                btn_modify.Enabled = true;
                string strGroup = row["TaxiGroup"].ToString();
                comboBoxEdit_taxigroup.Text = strGroup;
                imageCombo_serverList.Text = row["ServerId"].ToString();

                string strCompany = row["CompanyId"].ToString();
                comboBoxEdit_company.Text = strCompany;
                //if (MainForm.MyUserInfo.CompanyName!=Service.PowerConfig.MainCompanyName)
                //{
                //    comboBoxEdit_company.SelectedIndex = 0;
                //}
            }
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            DataRow row = this.gridView1.GetDataRow(this.gridView1.FocusedRowHandle);//
            if (row != null)
            {
                textEdit_Id.Text = row["id"].ToString();
                textEdit_taxiNo.Text = row["TaxiNo"].ToString();
                textEdit_Type.Text = row["TaxiType"].ToString();
                //textEdit_remark.Text = row["Remark"].ToString();                
                btn_modify.Enabled = true;
                string strGroup = row["TaxiGroup"].ToString();
                comboBoxEdit_taxigroup.Text = strGroup;
                imageCombo_serverList.Text = row["ServerId"].ToString();

                string strCompany = row["CompanyId"].ToString();
                comboBoxEdit_company.Text = strCompany;
                //if (MainForm.MyUserInfo.CompanyName != Service.PowerConfig.MainCompanyName)
                //{
                //    comboBoxEdit_company.SelectedIndex = 0;
                //}
            }
        }


        private void simpleButton_add_Click(object sender, EventArgs e)
        {
            if (btn_add.Tag.ToString() == "新增")
            {
                textEdit_Id.Text = "";
                textEdit_taxiNo.Text = "";
                textEdit_taxiNo.Enabled = true;
                textEdit_Type.Text = "";
                textEdit_Type.Enabled = true;
                //textEdit_remark.Text = "";
                comboBoxEdit_company.Text = "";
                
                //if (MainForm.MyUserInfo.CompanyName == Service.PowerConfig.MainCompanyName)
                //{
                //    comboBoxEdit_company.Enabled = true;
                //    btn_addCompany.Enabled = true;
                //}
                //else
                //{
                //    comboBoxEdit_company.SelectedIndex = 0;
                //}
                comboBoxEdit_company.Enabled = true;
                


                //textEdit_remark.Enabled = true;
                comboBoxEdit_taxigroup.Enabled = true;                
                comboBoxEdit_taxigroup.SelectedIndex = -1;
                imageCombo_serverList.Enabled = true;
                imageCombo_serverList.SelectedIndex =1;
                gridControl1.Enabled = false;
                btn_select.Enabled = false;
                btn_modify.Visible = false;
                btn_delete.Visible = false;
                btn_cancel.Visible = true;
                btn_cancel.Location = btn_modify.Location;
                btn_add.Tag = "保存";
                btn_add.Image = Properties.Resources.UserForm_btnsave001;
            }
            else
            {
                if (!CheckInput()) return;

                string strTaxiNo = textEdit_taxiNo.Text.Trim();
                string strType = textEdit_Type.Text.Trim();
                string //strRemark = textEdit_remark.Text.Trim();
                strRemark = comboBoxEdit_company.Text.Trim();
                int companyId = int.Parse(comboBoxEdit_company.Properties.Items[
                    comboBoxEdit_company.SelectedIndex].Value.ToString());

                int combindex = comboBoxEdit_taxigroup.SelectedIndex;
                int intGroup = 0; 
                if (combindex>=0)
                {
                    intGroup = int.Parse(_dtGroup.Rows[combindex]["id"].ToString());
                }                                    
                int serverid = int.Parse(
                      imageCombo_serverList.Properties.Items[
                      imageCombo_serverList.SelectedIndex].Value.ToString());
                try
                {
                    TaxiInfo taxi = new TaxiInfo
                    {
                        TaxiType = strType,      //类型
                        TaxiNo = strTaxiNo,      //牌照
                        Remark = strRemark,      //公司
                        TaxiGroupId = intGroup,  //广告分组
                        ServerId = serverid,     //服务器ID
                        SpeedOut = 70,           //超速阀值 
                        SpeedOutIsOpen = 1,      //超速是否报警   
                        StopOutTime = 12,        //超时停车阀值（单位为10分钟）
                        StopOutIsOpen = 1,       //超时停车是否报警
                        FatigueDravingTime = 10, //电池低电量阀值
                        FatigueDravingIsOpen =1,  //电池低电量是否报警

                        CompanyId = companyId
                       
                    };
                    if (MainForm.PositionService.TaxiInfoAdd(taxi))
                    {
                        XtraMessageBox.Show("添加成功");
                        gridControl1.Enabled = true;
                        btn_select.Enabled = true;
                        btn_delete.Visible = true;
                        btn_modify.Visible = true;
                        btn_cancel.Visible = false;

                        comboBoxEdit_taxigroup.Enabled = false;
                        imageCombo_serverList.Enabled = false;
                        textEdit_taxiNo.Enabled = false;
                        textEdit_Type.Enabled = false;
                        //textEdit_remark.Enabled = false;
                        comboBoxEdit_company.Enabled = false;
                        btn_addCompany.Enabled = false;
                        
                        btn_add.Tag = "新增";
                        btn_add.Image = Properties.Resources.UserForm_btnadd001;                        
                        _isAdd = true;
                        _thread = new Thread(BindGrid);
                        _thread.Start();
                    }
                    else
                    {
                        XtraMessageBox.Show("添加失败");
                    }
                }
                catch (Exception ex)
                {
                    Common.CommonRoutine.HandlingExceptions(ex, true);
                    return;
                }


                //taxi.TaxiType=
            }

        }

        private void simpleButton_modify_Click(object sender, EventArgs e)
        {
            if (textEdit_Id.Text == string.Empty)
            {
                XtraMessageBox.Show("请选择要修改的出租车！");
                return;
            }
            if (btn_modify.Tag.ToString() == "修改")
            {
                textEdit_taxiNo.Enabled = true;
                textEdit_Type.Enabled = true;
                //textEdit_remark.Enabled = true;


                //if (MainForm.MyUserInfo.CompanyName == Service.PowerConfig.MainCompanyName)
                //{
                //    comboBoxEdit_company.Enabled = true;
                //    btn_addCompany.Enabled = true;
                //}
                //else
                //{
                //    comboBoxEdit_company.SelectedIndex = 0;
                //} 
                comboBoxEdit_company.Enabled = true;
               
         



                comboBoxEdit_taxigroup.Enabled = true;                
                imageCombo_serverList.Enabled = true;                


                gridControl1.Enabled = false;
                btn_select.Enabled = false;
                btn_delete.Visible = false;
                btn_cancel.Visible = true;
                btn_cancel.Location = btn_modify.Location;
                btn_modify.Location = btn_add.Location;
                btn_add.Visible = false;
                btn_modify.Tag = "保存";
                btn_modify.Image = Properties.Resources.UserForm_btnsave001;
            }
            else
            {
                if (!CheckInput()) return;
                string strTaxiNo = textEdit_taxiNo.Text.Trim();
                string strType = textEdit_Type.Text.Trim();
                string //strRemark = textEdit_remark.Text.Trim();
                strRemark = comboBoxEdit_company.Text.Trim();
                string strId = textEdit_Id.Text.Trim();
                //int combindex = comboBoxEdit_taxigroup.SelectedIndex;
                //int intGroup = int.Parse(_dtGroup.Rows[combindex]["id"].ToString());

                int combindex = comboBoxEdit_taxigroup.SelectedIndex;
                int intGroup = 0;
                if (combindex >= 0)
                {
                    intGroup = int.Parse(_dtGroup.Rows[combindex]["id"].ToString());
                }                       

                
                int serverid = int.Parse(
                        imageCombo_serverList.Properties.Items[
                        imageCombo_serverList.SelectedIndex].Value.ToString());

                int companyId = int.Parse(comboBoxEdit_company.Properties.Items[
                 comboBoxEdit_company.SelectedIndex].Value.ToString());

                TaxiInfo taxi = MainForm.PositionService.TaxiGetModel(int.Parse(strId));
                if (taxi != null)
                {
                    taxi.TaxiType = strType;
                    taxi.TaxiNo = strTaxiNo;
                    taxi.Remark = strRemark;
                    taxi.TaxiGroupId = intGroup;
                    taxi.ServerId = serverid;
                    taxi.CompanyId = companyId;
                }
                try
                {
                    if (MainForm.PositionService.TaxiInfoUpdate(taxi))
                    {
                        XtraMessageBox.Show("修改成功！");

                        gridControl1.Enabled = true;
                        btn_select.Enabled = true;
                        btn_delete.Visible = true;
                        btn_add.Visible = true;
                        btn_modify.Location = btn_cancel.Location;
                        btn_cancel.Visible = false;
                        btn_modify.Tag = "修改";
                        btn_modify.Image = Properties.Resources.UserForm_btnmodify001;
                        comboBoxEdit_taxigroup.Enabled = false;
                        imageCombo_serverList.Enabled = false;
                        textEdit_taxiNo.Enabled = false;
                        textEdit_Type.Enabled = false;
                        //textEdit_remark.Enabled = false;
                        comboBoxEdit_company.Enabled = false;
                        btn_addCompany.Enabled = false;
  
                        //BindGrid();
                        _thread =new Thread(BindGrid);
                        _thread.Start();
                    }
                    else
                    {
                        XtraMessageBox.Show("修改失败！");
                    }
                }
                catch (Exception ex)
                {
                    Common.CommonRoutine.HandlingExceptions(ex, true);
                    return;
                }
            }
        }

        private void simpleButton_delete_Click(object sender, EventArgs e)
        {
            DataRow row = this.gridView1.GetDataRow(this.gridView1.FocusedRowHandle);
            string id;
            if (row == null)
            {
                XtraMessageBox.Show("请选择要删除的出租车！");
                return;
            }
            id = row["id"].ToString();
            //if (textEdit_Id.Text == string.Empty)
            //{
            //    XtraMessageBox.Show("请选择要删除的出租车！");
            //    return;
            //}
            if (XtraMessageBox.Show("确认删除流水号为【" + id + "】的记录吗？", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                try
                {
                    if (MainForm.PositionService.TaxiInfoDelete(int.Parse(id)))
                    {
                        XtraMessageBox.Show("删除成功！");
                        _thread = new Thread(BindGrid);
                        _thread.Start();
                    }
                    else
                    {
                        XtraMessageBox.Show("删除失败！");
                    }
                }
                catch (Exception ex)
                {
                    Common.CommonRoutine.HandlingExceptions(ex, true);
                }

            }
        }

        private void simpleButton_Select_Click(object sender, EventArgs e)
        {            
            gridView1.GroupPanelText = "数据加载中...";
            btn_select.Enabled = false;
            _thread = new Thread(BindGrid);
            _thread.Start();
        }

        private void simpleButton_cancle_Click(object sender, EventArgs e)
        {
            gridView1_RowClick(null,null);
            gridControl1.Enabled = true;
            btn_select.Enabled = true;
            btn_delete.Visible = true;
            btn_cancel.Visible = false;
            btn_add.Visible = true;
            btn_add.Tag = "新增";
            btn_add.Image = Properties.Resources.UserForm_btnadd001;
            btn_modify.Visible = true;
            btn_modify.Tag = "修改";
            btn_modify.Image = Properties.Resources.UserForm_btnmodify001;
            btn_modify.Location = btn_cancel.Location;
            comboBoxEdit_taxigroup.Enabled = false;
            imageCombo_serverList.Enabled = false;
            textEdit_taxiNo.Enabled = false;
            textEdit_Type.Enabled = false;
            //textEdit_remark.Enabled = false;
            comboBoxEdit_company.Enabled = false;
            btn_addCompany.Enabled = false;
        }

        private bool CheckInput()
        {
            string strTaxiNo = textEdit_taxiNo.Text.Trim();
            string strType = textEdit_Type.Text.Trim();
            if (strTaxiNo == string.Empty)
            {
                XtraMessageBox.Show("出租车牌照号码不能为空");
                textEdit_taxiNo.Focus();
                return false;
            }
            if (strType == string.Empty)
            {
                XtraMessageBox.Show("出租车牌车型不能为空");
                textEdit_Type.Focus();
                return false;
            }
            if (Encoding.GetEncoding("GBK").GetBytes(strTaxiNo).Length > 8)
            {
                XtraMessageBox.Show("出租车牌照号码输入长度太长");
                textEdit_taxiNo.Focus();
                return false;
            }
            if (Encoding.GetEncoding("GBK").GetBytes(strType).Length > 12)
            {
                XtraMessageBox.Show("出租车车型输入长度太长（请输入小于6个汉字）");
                textEdit_Type.Focus();
                return false;
            }
            //if (textEdit_remark.Text.Length>50)
            //{
            //    XtraMessageBox.Show("公司名称太长，最长为50字符");
            //    textEdit_remark.Focus();
            //    return false;
            //}
            if (comboBoxEdit_company.SelectedIndex<0
                ||comboBoxEdit_company.Text=="")
            {
                XtraMessageBox.Show("请选择出租车所属公司");
                comboBoxEdit_company.Focus();
                return false;
            }
             

            //if (comboBoxEdit_taxigroup.SelectedIndex < 0)
            //{
            //    XtraMessageBox.Show("请选择出租车所属广告分组");
            //    comboBoxEdit_taxigroup.Focus();
            //    return false;
            //}
            if(imageCombo_serverList.SelectedIndex==0)
            {
                XtraMessageBox.Show("请选择该出租车所使用的服务器！");
                imageCombo_serverList.Focus();
                return false;
            }
            return true;
        }

       #region  窗体控件操作、效果
        Point _mouseOff;
        bool _leftFlag;
        private void Taxi_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _mouseOff = new Point(-e.X, -e.Y);
                _leftFlag = true;
            }
        }

        private void Taxi_MouseMove(object sender, MouseEventArgs e)
        {
            if (_leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(_mouseOff.X, _mouseOff.Y);
                Location = mouseSet;
            }
        }

        private void Taxi_MouseUp(object sender, MouseEventArgs e)
        {
            if (_leftFlag)
            {
                _leftFlag = false;
            }
        }

        private void pictureEdit_exit_MouseHover(object sender, EventArgs e)
        {
            pictureBox1.Image = Properties.Resources.snedSmsexit ;
            Cursor = Cursors.Hand;
        }

        private void pictureEdit_exit_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.Image = Properties.Resources.snedSmsexitPressDown;

            Cursor = Cursors.Arrow;

        }

        private void pictureEdit_exit_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btn_MouseHover(object sender, EventArgs e)
        {
            Cursor = Cursors.Hand;
        }

        private void btn_MouseLeave(object sender, EventArgs e)
        {
            Cursor = Cursors.Arrow;
        }
        private void Form_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Close();
            }
        }
      
#endregion

        private void btn_exportToExcel_Click(object sender, EventArgs e)
        {
            saveFileDialog1.FileName = "出租车列表";
            saveFileDialog1.Filter = "Excel文件(*.xls)|*.xls";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                gridView1.ExportToXls(saveFileDialog1.FileName);
                XtraMessageBox.Show("Excel导出完成！");
            }
        }

        private void TaxiFrom_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_thread != null)
            {
                _thread.Abort();
            }
        }

        private void btn_addCompany_Click(object sender, EventArgs e)
        {
            CompanyForm form = new CompanyForm();
            form.ShowDialog();
            DataSet dsCompany = MainForm.PositionService.CompanyGetList("");
            if (dsCompany != null && dsCompany.Tables.Count > 0)
            {
                comboBoxEdit_company.Properties.Items.Clear();
                foreach (DataRow row in dsCompany.Tables[0].Rows)
                {
                    string id = row["Id"].ToString();
                    string name = row["CompanyName"].ToString();
                    ImageComboBoxItem item = new ImageComboBoxItem();
                    item.Description = name;
                    item.Value = id;
                    BeginInvoke(new MethodInvoker(() =>
                    {
                        comboBoxEdit_company.Properties.Items.Add(item);
                    }));
                }
            }
        }

        private void textEdit_condition_KeyPress(object sender, KeyPressEventArgs e)
        {
             
            if ((Keys)e.KeyChar == Keys.Enter)
            {
                simpleButton_Select_Click(null, null);
            }
         
        }

      

        //private void simpleButton1_Click(object sender, EventArgs e)
        //{
        //    int count = 0;
        //    for(int i=0;i<10000;i++)
        //    {
        //        //System.Threading.Thread.Sleep(10);
        //        string taxiNo = "鄂C" + i.ToString();
        //        string taxiType = "奥迪A6";
        //        string Remark = "光通讯科技";
        //        string taxigroup = "15";
        //         TaxiInfo taxi = new TaxiInfo
        //            {
        //                TaxiType = taxiType,
        //                TaxiNo = taxiNo,
        //                Remark = Remark,
        //                TaxiGroupId = int.Parse(taxigroup)
        //            };
        //         if (MainForm.PositionService.TaxiInfoAdd(taxi)) 
        //             count++;
        //    }
        //}

    }
}